//-------------------------------------------------------------------
//	Copyright (c) 2010-2012  Zhirnov Andrey
//	This file is part of the "UXGEN" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#ifndef _UX_RESOURCE_METACUSTOM_OBJECT_H
#define _UX_RESOURCE_METACUSTOM_OBJECT_H

#include "CResourceManager.h"

namespace Engine
{
namespace UXTypes
{

	//
	// Resource Setter
	//

	class CResourceSetter : public IMetaCustomObject
	{
	private:
		e_resource::type		_eResType;

	public:
		CResourceSetter(e_resource::type type): _eResType(type) {}

		virtual bool SetValue(void *pObj, const void * const pValue, e_value::type eType)
		{
			if ( eType != e_value::STRING )
				return false;

			CResourcePtr	p_res	= nullptr;
			CCore		*	p_core	= nullptr;

			if ( GLOBAL::RESMAN()->Load( _eResType, p_res,
					(*creint_cast< const string *>( pValue )).cstr(), 0 ) )
			{
				memcpy( pObj, &p_res, sizeof(p_res) );
				return true;
			}

			return false;
		}

		virtual bool GetValue(void *pObj, void * pValue, e_value::type eType)
		{
			return false;
		}

		virtual bool GetValue(void *pObj, string &sValue)
		{
			return false;
		}

		virtual bool AddField(const void *pObj, const void *pField, const char *pName, e_value::type eType)
		{
			return false;
		}

		virtual bool GetField(const string &sName, IMetaBaseType *&pField)
		{
			return false;
		}

		virtual bool GetField(uint uNumb, IMetaBaseType *&pField)
		{
			return false;
		}

		virtual void Free()
		{
			delete this;
		}
	};


//-------------------------------------------------------------------

}	// UXTypes
}	// Engine

#endif	// _UX_RESOURCE_METACUSTOM_OBJECT_H